<template>
    <div class="latiao">
        <div class="la-one" v-for="(item, index) in uanam" :key="index">

            <div class="la-one-r">

                <div class="la-one-q">{{ item.name }}</div>
                <div class="la-one-qq"> {{ item.price }}元/袋</div>

            </div>

            <div class="la-one-w">
                <div class="la-one-ww" @click="getName1(index)">-</div>
                <div class="la-one-e">{{ item.status }}</div>
                <div class="la-one-ee" @click="getName(index)">+</div>
            </div>
            <!-- <div class="la-one-w">
                <div class="la-one-ww" @click="getName(item)">-</div>
                <div class="la-one-e">{{  item.status }}</div>
                <div class="la-one-ee" @click="getName(item)" >+</div>
            </div> -->
        </div>
        <!-- <div class="la-one-rr" @click="uanm = true">支付({{ getName3() }})</div>
        <div class="la-two" v-if=" uanm" @click="uanm = false">
            <div class="la-two-qq">总价格:{{ getName3() }}</div>
        </div> -->
        <div class="la-one-rr" @click="getName4()">支付({{ ge }})</div>
        <div class="la-two" v-if="uanm" @click="uanm = false">
            <div class="la-two-qq">总价格:{{ ge }}</div>
        </div>

    </div>
</template>

<script>
export default {
    name: "",
    /*1. Vue扩展 */
    extends: "", // extends和mixins都扩展逻辑，需要重点放前面
    mixins: [],
    components: {},
    /* 2. Vue数据 */
    props: {},
    model: { prop: "", event: "" }, // model 会使用到 props
    data() {
        return {
            uanm: false,
            uanam: [],
            ge: 0,

        };
    },
    computed: {},
    watch: {}, // watch 监控的是 props 和 data，有必要时监控computed
    /* 3. Vue资源 */
    filters: {},
    directives: {},
    /* 4. Vue生命周期 */
    created() {
        const qwe = this.getShopList()
        //  {result[]}
        this.uanam = qwe.result
    },
    mounted() { },
    destroy() { },

    /* 5. Vue方法 */
    methods: {
        getShopList() {
            const data = {
                result: [
                    {
                        name: "苹果",
                        price: 10,
                        status: 0
                    },
                    {
                        name: "栗子",
                        price: 20,
                        status: 0
                    },
                    {
                        name: "香蕉",
                        price: 30,
                        status: 0
                    },
                    {
                        name: "菠萝",
                        price: 40,
                        status: 0
                    },
                    {
                        name: "西红柿",
                        price: 5,
                        status: 0
                    },
                ],
            };
            return data
        },
        getName(as) {
            this.uanam[as].status = this.uanam[as].status + 1
            this.getName3()
        },
        getName1(as) {
            if (this.uanam[as].status > 0) {
                this.uanam[as].status = this.uanam[as].status - 1
            }
            this.getName3()
        },
        //   getName(as){
        //     as.status = as.status + 1
        //   },
        //   getName1(as){
        //     if (as.status > 0) {
        //         as.status = as.status - 1
        //     }

        //   },
        //     getName3(){
        //        let ge = 0
        //         for (let index = 0; index < this.uanam.length; index++) {
        //             ge =   ge +  this.uanam[index]. price * this.uanam[index]. status
        //              }
        //   return ge
        //     },
        getName3() {
            this.ge = 0
            for (let index = 0; index < this.uanam.length; index++) {
                this.ge = this.ge + this.uanam[index].price * this.uanam[index].status
            }
        },
        getName4 () {
            this.getName3()
            this.uanm = true
        },
    }
};
</script>


<style scoped lang="scss">
.latiao {
    width: 100%;
    height: 100vh;
    border: 1px solid red;

    .la-one {
        height: 150px;
        margin: 15px 10px 0 10px;
        border: 1px solid red;
        display: flex;
        background-color: antiquewhite;

        .la-one-r {
            margin: 15px 10px 0 10px;

            .la-one-q {
                height: 35px;
                border: 1px solid red;
                width: 110px;
                text-align: center;
                line-height: 35px;
                color: brown;
            }

            .la-one-qq {
                height: 35px;
                border: 1px solid red;
                width: 110px;
                text-align: center;
                line-height: 35px;
                margin-top: 15px;
                color: brown;
            }

            .la-one-qqq {
                height: 35px;
                border: 1px solid red;
                width: 110px;
                text-align: center;
                line-height: 35px;
                margin-top: 15px;
                color: brown;
            }
        }

        .la-one-w {
            margin-left: auto;
            display: flex;
            align-items: center;

            .la-one-ww {
                height: 35px;
                width: 35px;
                border: 1px solid red;
                text-align: center;
                line-height: 35px;
                font-size: 20px;
                font-weight: 500;
                color: red;
                border-radius: 5px;
            }

            .la-one-e {
                height: 35px;
                width: 35px;
                border: 1px solid red;
                text-align: center;
                line-height: 35px;
                font-size: 20px;
                font-weight: 500;
                margin-left: 10px;
                color: red;
                border-radius: 5px;
            }

            .la-one-ee {
                height: 35px;
                width: 35px;
                border: 1px solid red;
                text-align: center;
                line-height: 35px;
                font-size: 20px;
                font-weight: 500;
                margin-left: 10px;
                color: red;
                border-radius: 5px;
            }
        }
    }

    .la-one-rr {
        height: 40px;
        border: 1px solid red;
        border-radius: 10px;
        background-color: blue;
        font-size: 17px;
        font-weight: 600;
        color: aliceblue;
        text-align: center;
        line-height: 40px;
        position: fixed;
        bottom: 0;
        right: 15px;
        left: 15px;


    }

    .la-two {
        bottom: 0;
        top: 0;
        left: 0;
        right: 0;
        position: fixed;
        background-color: rgba(0, 0, 0, 0.2);
        justify-content: center;
        align-items: center;
        display: flex;

        .la-two-qq {
            line-height: 60px;
            height: 60px;
            width: 300px;
            text-align: center;
            font-size: 24px;
            font-weight: 600;
            color: red;
            background-color: white;
            border-radius: 10px;
        }
    }
}
</style>